home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / UNHQX.ZIP / unhqx.txt < prev   
Internet Message Format  |  1995-03-07  |  5KB

  1. From: iacullwd@acasun.eckerd.edu (Walter D. Iacullo)
  2. Newsgroups: alt.binaries.multimedia
  3. Subject: Pascal Program for DeBinHexing (.hqx) files
  4. Date: 4 Jan 1995 23:29:07 -0500
  5. Organization: Eckerd College, St. Petersburg, Florida
  6.  
  7.  
  8. The second part is a program for Turbo Pascal 7.0.  It ONLY WORKS WITH
  9. 7.0!!!  The following is more info on the program.
  10.  
  11.    Turbo Pascal 7.0 UnHQX Object    
  12.    =============================
  13.     - by Robert Rothenburg Walking-Owl <robert.rothenburg@asb.com> 
  14.       CopyLeft, 1994
  15.  
  16.  
  17.    How the UnHQX unit works:
  18.    =========================
  19.  
  20.     - You must first locate where the "(This file must be converted..."
  21.       message is in the file (raw FilePos) and pass that to Init.  Init
  22.       reads the the initial header information and exits will the file-
  23.       position at the start of the data fork. (Note: you must manually
  24.       set FilePtr to 0 to signify relative position in each fork!)
  25.  
  26.       For example,
  27.  
  28.         var Filter: HQX;
  29.             Origin: LongInt;
  30.             f: file;
  31.         begin
  32.           Assign(f,'FileName.hqx');
  33.           ReSet(f,1);
  34.           repeat
  35.             ...       { Search file for "(This file must be converted". }
  36.             ...       { Set Origin to that position ...                 }
  37.           until Found;
  38.           Filter.Init(f,Origin);
  39.           if Filter.Header.FileCRC <> Filter.Header.CRC
  40.             then { Bad CRC! }
  41.             else ...
  42.             
  43.             ...      { Filter.Header contains the header information   }
  44.           
  45.           Filter.FilePtr := 0;  { Initialize filepointer for fork      }
  46.           Filter.CRC := 0;      { Initialize CRC for fork              }
  47.           for i := 1 to Filter.Header.DataLen
  48.             do ...   { Read Filter.Header.DataLen characters ...       }
  49.           ActualCRC   := fCRC;          { What CRC actually was        }
  50.           DataForkCRC := Filter.fGetW;  { What CRC is supposed to be   }
  51.  
  52.             ...      { Repeat the same for the Resource Fork           }
  53.  
  54.           Filter.Done;
  55.         end;
  56.     
  57.       { Note: fCRC finalizes the CRC and returns the value.  You must  }
  58.       {       then read the CRC, check if valid, and then reinitialize }
  59.       {       the CRC to 0!                                            }
  60.  
  61.     - Use the public f-functions only to get characters from the file! 
  62.       (ie. fGetC, fGetBlock, fGetW, fGetL, fSkip or fSeek, and fCRC).
  63.  
  64.     - fGetC is the root function, which handles the required bookkeeping,
  65.       mainly because of the run-length encoding used by BinHex 4.0 files.
  66.  
  67.  
  68.                ReadChar --> Fetch ---> Decode ----> PutBits
  69.                              |                       |
  70.         fSkip --> fSeek --> fGetC <-- UpdateCRC <-- Retrieve
  71.                              |                       
  72.                             fGetBlock  --->+        
  73.                              |             +--> Init
  74.                             fGetW, fGetL ->+
  75.  
  76.       If the Run-Length flag is set, fGetC continues to send the repeated 
  77.       character when called for the specified number of times.
  78.  
  79.       If more characters need to be decoded, Fetch is called.  (Fetch
  80.       gets raw characters from the file, then decodes them and adds them
  81.       to the buffer for Retrieve.  ReadChar uses a Buffer to minimize
  82.       disk-reads and speed the process up).
  83.  
  84.       fGetC then calls retrieve and sends the character unless it's 0x90
  85.       (ASCII #144) which signifies a run-length code.  The number of
  86.       repetitions is read in and the Run-Length flag is set.
  87.  
  88.       fGetC automatically calls UpdateCRC.  When you are done reading the
  89.       fork, call fCRC to finalize the CRC.  (You must initialize the CRC
  90.       before reading the fork!)
  91.       
  92.       fSeek and fGetBlock use fGetC.  The other functions use either fSeek
  93.       or fGetBlock.
  94.  
  95.    Improvements?
  96.    =============
  97.       
  98.     UnHQX is a bit slow for large files (about 15 seconds to decode a
  99.     550k .sit.hqx file on a 486/33 machine).  Inline code has been used
  100.     to improve performace--although the original Pascal source is left
  101.     in {}-brackets for reference.
  102.  
  103.     I've played with various methods such as increasing the disk-buffer
  104.     size or fetching more than four characters at a time... no notice-
  105.     able effect on the speed has come of it, however.
  106.  
  107.    Other Important Stuff:
  108.    ======================
  109.  
  110.     Remember to convert carriage-returns, line-feeds, spaces, slashes and
  111.     periods in Mac filenames to other characters (usu. '_') which are acc-
  112.     eptable to DOS as filenames!
  113.  
  114.     Mac date and time stamps are usu. stored in LSB Unix-time format PLUS
  115.     0x7c25b080. (Get the time without using SwapLong, subtract $7C25B080,
  116.     and then adjust for the time-zone, usu. stored in the TZ variable).
  117.  
  118.